package cn.kgc.detail.controller;

import cn.kgc.detail.pojo.Detail;
import cn.kgc.detail.pojo.ResultEntity;
import cn.kgc.detail.pojo.Sort;
import cn.kgc.detail.service.DetailService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RestController
public class DetailController {
    @Resource
    DetailService detailService;

    @RequestMapping("/selectDetail")
    public ResultEntity<List<Detail>> selectDetail(@RequestParam(value = "sortid",defaultValue = "0")Integer sortid,
                                                   @RequestParam(value = "title",defaultValue = "")String title){
        List<Detail> detailList = detailService.selectAll(title, sortid);
        return ResultEntity.successWithoutData(detailList);
    }

    @RequestMapping("/getSortList")
    public  ResultEntity<List<Sort>> getSortList(){
        List<Sort> sortList = detailService.selectAllSort();
        return  ResultEntity.successWithoutData(sortList);

    }

    @RequestMapping("/updateDetail")
    public  ResultEntity<Integer> updateDetail(@RequestBody Detail detail){
        Integer updateDetail = detailService.updateDetail(detail);
        return ResultEntity.successWithoutData(updateDetail);
    }

    @RequestMapping("/getDetailById")
    public  ResultEntity<Detail> getDetailByI(Integer id){
        Detail allById = detailService.selectAllById(id);
        return ResultEntity.successWithoutData(allById);
    }

}
